package web;

import general.OutputProvider;
import java.io.Writer;

/**
 *
 * @author Alejandro
 */
public class HtmlOutput extends OutputProvider {

    public HtmlOutput(Writer out) {
        this.out = out;
    }

    public void putSuccessReport(String report) {
        echo("<div class=\"success\">Success: " + report + "</div>");
    }

    public void putErrorReport(String report, String message) {
        if (!message.isEmpty()) {
            echo("<div class=\"error\"><p>Error: " + report + "<br /><span onclick=\"onShowErrorMessage(); \">more info</span></p><p style=\"display: none; \" id=\"error_description\">" + message + "</p></div>");
        } else {
            echo("<div class=\"error\">Error: " + report + "</div>");
        }
    }

    public void putTableHeader(String name, String caption, boolean isActive) {
        if (isActive) {
            echo("<th><input type=\"submit\" class=\"sorted_header\" name=\"" + name + "\" value=\"" + caption + "\" /></th>");
        } else {
            echo("<th><input type=\"submit\" class=\"header\" name=\"" + name + "\" value=\"" + caption + "\" /></th>");
        }
    }

    public void startTableRow(String rowClass) {
        echo("<tr class=\"" + rowClass + "\">");
    }

    public void endTableRow() {
        echo("</tr>");
    }

    public void putTableIndexCell(String name) {
        echo("<td><input type=\"checkbox\" id=\"row_" + name + "\" name=\"row_" + name + "\" class=\"checkbox\" onchange=\"checkRowSelection(); \" ondblclick=\" return checkAll(this); \" /></td>");
    }

    public void putTableCell(String caption) {
        echo("<td>" + caption + "</td>");
    }

    public void putTableTextCell(String name, boolean flag) {
        if (flag) {
            echo("<td><input type=\"text\" id=\"editrow_" + name + "\" name=\"editrow_" + name + "\" value=\"" + name + "\" readonly class=\"texteven\" /></td>");
        } else {
            echo("<td><input type=\"text\" id=\"editrow_" + name + "\" name=\"editrow_" + name + "\" value=\"" + name + "\" readonly class=\"textodd\" /></td>");
        }
    }

    public void putHeader2(String caption) {
        echo("<h2>" + caption + "</h2>");
    }

    public void putBlockLabel(String forWhat, String caption) {
        echo("<label class=\"block\" for=\"" + forWhat + "\">" + caption + "</label>");
    }

    public void putInlineLabel(String forWhat, String caption) {
        echo("<label class=\"inline\" for=\"" + forWhat + "\">" + caption + "</label>");
    }

    public void putTextField(String name, String value) {
        echo("<input type=\"text\" id=\"" + name + "\" name=\"" + name + "\" class=\"text\" value=\"" + value + "\" />");
        echo("<div class=\"clear\"></div>");
    }

    public void putSubmit(String caption, String name) {
        echo("<input type=\"submit\" value=\"" + caption + "\" name=\"" + name + "\" id=\"" + name + "\" class=\"submit\" />");
    }

    public void putSelectOption(String value, String caption, boolean isSelected) {
        if (isSelected) {
            echo("<option selected=\"selected\" value=\"" + value + "\">" + caption + "</option>");
        } else {
            echo("<option value=\"" + value + "\">" + caption + "</option>");
        }
    }
}
